package com.cjl.multi_thread.error;

public class ErrorAccount {
    private String name;
    private int money;

    private static final Object object = new Object();

    public ErrorAccount(String name, int money) {
        this.name = name;
        this.money = money;
    }

    public String getName() {
        return name;
    }

    public int getMoney(int x) {
        synchronized (object){
            System.out.println("Account.getMoney---"+Thread.currentThread().getName()+"Step:"+x);
            return money;
        }
    }

    public void setMoney(int money) {
        synchronized (object){
            System.out.println("Account.setMoney---");
            this.money = money;
        }
    }

    @Override
    public String toString() {
        return "Account{" +
                "name='" + name + '\'' +
                ", money=" + money +
                '}';
    }
}
